﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace is_it_messy
{
    class Util
    {

        public static List<FileData> GetFilesInfo(String path, bool recursion)
        {
            DirectoryInfo dir = new DirectoryInfo(path);
            if (recursion)
            {
                return GetFilesInfo(path);
            }
            else
            {
                return GetFilesInfoNoRecursion(path);
            }
        }

        public static List<FileData> GetFilesInfo(String path)
        {
            DirectoryInfo dir = new DirectoryInfo(path);
            List<FileData> data = GetFilesInfo(dir);
            return data;
        }
        private static List<FileData> GetFilesInfo(DirectoryInfo dir)
        {
            List<FileData> data = new List<FileData>();
            foreach (DirectoryInfo nextDir in dir.GetDirectories())
            {
                data.AddRange(GetFilesInfo(nextDir));
            }

            foreach (FileInfo file in dir.GetFiles())
            {
                data.Add(new FileData(file));
            }
            return data;
        }

        public static List<FileData> GetFilesInfoNoRecursion(String path)
        {
            DirectoryInfo dir = new DirectoryInfo(path);
            List<FileData> data = GetFilesInfoNoRecursion(dir);
            return data;
        }
        private static List<FileData> GetFilesInfoNoRecursion(DirectoryInfo dir)
        {
            List<FileData> data = new List<FileData>();
            
            foreach (FileInfo file in dir.GetFiles())
            {
                data.Add(new FileData(file));
            }
            return data;
        }

    }
}
